home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows (5th Edition) / Programming Windows, 5th ed. - Companion CD (097-0002183)(1999).iso / Chap21 / EdrTest / EdrTest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-09  |  2.4 KB  |  79 lines

  1. /*--------------------------------------------------------
  2.    EDRTEST.C -- Program using EDRLIB dynamic-link library
  3.                 (c) Charles Petzold, 1998
  4.   --------------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7. #include "edrlib.h"
  8.  
  9. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  10.  
  11. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  12.                     PSTR szCmdLine, int iCmdShow)
  13. {
  14.      static TCHAR szAppName[] = TEXT ("StrProg") ;
  15.      HWND         hwnd ;
  16.      MSG          msg ;
  17.      WNDCLASS     wndclass ;
  18.  
  19.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  20.      wndclass.lpfnWndProc   = WndProc ;
  21.      wndclass.cbClsExtra    = 0 ;
  22.      wndclass.cbWndExtra    = 0 ;
  23.      wndclass.hInstance     = hInstance ;
  24.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  25.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  26.      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  27.      wndclass.lpszMenuName  = NULL ;
  28.      wndclass.lpszClassName = szAppName ;
  29.      
  30.      if (!RegisterClass (&wndclass))
  31.      {
  32.           MessageBox (NULL, TEXT ("This program requires Windows NT!"),
  33.                       szAppName, MB_ICONERROR) ;
  34.           return 0 ;
  35.      }
  36.      
  37.      hwnd = CreateWindow (szAppName, TEXT ("DLL Demonstration Program"),
  38.                           WS_OVERLAPPEDWINDOW,
  39.                           CW_USEDEFAULT, CW_USEDEFAULT,
  40.                           CW_USEDEFAULT, CW_USEDEFAULT,
  41.                           NULL, NULL, hInstance, NULL) ;
  42.      
  43.      ShowWindow (hwnd, iCmdShow) ;
  44.      UpdateWindow (hwnd) ;
  45.      
  46.      while (GetMessage (&msg, NULL, 0, 0))
  47.      {
  48.           TranslateMessage (&msg) ;
  49.           DispatchMessage (&msg) ;
  50.      }
  51.      return msg.wParam ;
  52. }
  53.  
  54. LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  55. {
  56.      HDC         hdc ;
  57.      PAINTSTRUCT ps ;
  58.      RECT        rect ;
  59.      
  60.      switch (message)
  61.      {
  62.      case WM_PAINT:
  63.           hdc = BeginPaint (hwnd, &ps) ;
  64.           
  65.           GetClientRect (hwnd, &rect) ;
  66.           
  67.           EdrCenterText (hdc, &rect, 
  68.                          TEXT ("This string was displayed by a DLL")) ;
  69.           
  70.           EndPaint (hwnd, &ps) ;
  71.           return 0 ;
  72.           
  73.      case WM_DESTROY:
  74.           PostQuitMessage (0) ;
  75.           return 0 ;
  76.      }
  77.      return DefWindowProc (hwnd, message, wParam, lParam) ;
  78. }
  79.